package homework;

import java.util.Arrays;

public class LeetCode35 {
    public int lastStoneWeight(int[] stones) {
        int len=stones.length;
        while (len>1){
            Arrays.sort(stones,0,len-1);
            int a=Math.abs(stones[len-1]-stones[len-2]);
            if(a==0){
                len-=2;
            }else {
                len--;
                stones[len-1]=a;
            }
        }
        return stones[0];
    }
}
